<?php


/**
 * Default controller class.
 */
class Default_Controller{


	/**
	 * Default action for this controller
	 */
	function default_action(){

		check_login();
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}


	/**
	 * Login
	 */
	function login_action($msg_type = null){

		$main_view = new Main_View();
		$main_view->login($msg_type);
		$main_view->generate_html();
	}


	/**
	 * Logout
	 */
	function logout_action(){
		
		// kill session and delete cookie
		$_SESSION = array();
		if(isset($_COOKIE[session_name()])){
			setcookie(session_name(), '', time() - 42000, '/');
			$_COOKIE = array();
		}
		
		session_destroy();
		
		// go to login
		$this->login_action();
	}


	/**
	 * Sum
	 */
	function sum_action(){

		check_login();
		
		$sum_view = new Sum_View();
		$sum_view->sum();
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}


	/**
	 * Sum with ajax
	 */
	function sumajax_action(){

		check_login();
		
		$sum_view = new Sum_View();
		$sum_view->sum_ajax();
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}


	/**
	 * Calculates sum
	 */
	function calculate_action(){

		check_login();
		
		$sum = new Example();
		$sum_result = $sum->sum($_POST['num1'], $_POST['num2']);
		
		$sum_view = new Sum_View();
		$sum_view->sum($sum_result);
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}


	/**
	 * Calculates sum with ajax
	 */
	function calculateajax_action(){

		check_login();
		
		$sum = new Example();
		$sum_result = $sum->sum($_POST['num1'], $_POST['num2']);
		
		$sum_view = new Sum_View();
		$sum_view->sum_result_ajax($sum_result);
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	
	/**
	 * Sum
	 */
	function test_action(){

		check_login();
		
		$sum_view = new Sum_View();
		$sum_view->test();
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	/**
	 * Sum
	 */
	function chat_action(){
	
		check_login();
	
		$sum_view = new Sum_View();
		$sum_view->chat();
	
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	/**
	 * Calculates sum with ajax
	 */
	function readxml_action(){

		check_login();
		
		$filename = "C:\Users\jbeslic\Downloads/prometTekucegRacunaUKunamajopa.xml";
		
		$read = new Pbz();
		$return = $read->read_xml($filename);
		
		if ($return){
			$sum_view = new Sum_View();
			$sum_view->read_xml($return);
		}
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	/**
	 * Calculates sum with ajax
	 */
	function showtransactions_action(){

		check_login();
		
		$r = new Pbz();
		$transactions = $r->restore_transactions($_GET['year'],@$_GET['month'],@$_GET['day'],@$_GET['owner_id']);
		$amount = $r->amount_and_flag($transactions);
		
		//prs($test);
		
		$view = new Sum_View();
		$view->restore_transactions($transactions, $amount);
		
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	/**
	 * Calculates sum with ajax
	 */
	function showtransactions2_action(){
	
		check_login();
	
		$view = new Sum_View();
		$view->restore_transactions2();
	
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	/**
	 * Calculates sum with ajax
	 */
	function showtransactions3_action(){
	
		check_login();
	
		$view = new Sum_View();
		$view->restore_transactions3();
	
		$main_view = new Main_View();
		$main_view->generate_html();
	}
	
	
	
}
